package com.henushang.ranking.util;

import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

import org.apache.log4j.Logger;

public class PropertiesUtil {

    private static final Logger LOGGER = Logger.getLogger(PropertiesUtil.class);
    private Properties instance = null;
    private Map<String, Object> propMap = null;

    public PropertiesUtil(String path) {
        instance = new Properties();
        try {
            @SuppressWarnings("rawtypes")
            Class clazz = Class.forName("com.henushang.ranking.util.PropertiesUtil");
            instance.load(clazz.getResourceAsStream("/" + path));
        } catch (Exception e) {
            LOGGER.error(String.format("load properties file %s error!", path), e);
        }
    }

    public synchronized Map<String, Object> getPropMap() {
        if (propMap == null) {
            propMap = new HashMap<>();
            for (Object key : instance.keySet()) {
                propMap.put(key.toString(), instance.get(key));
            }
        }

        return propMap;
    }
}
